package com.zjw.service.message.impl;

import com.zjw.service.message.IMessageDataBase;
import com.zjw.service.message.Message;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 内存的直接存储
 */
public class MemoryMessageDataBase implements IMessageDataBase {

    private final Map<Long, List<Message>> store = new ConcurrentHashMap<>();

    @Override
    public void insertMessageList(Message message) {
        List<Message> messages = store.computeIfAbsent(message.getToId(), it -> new ArrayList<>());
        messages.add(message);
    }

    @Override
    public List<Message> getMessageList(long userId) {
        return store.get(userId);
    }

    @Override
    public List<Message> removeMessageList(long userId) {
        return store.remove(userId);
    }
}
